package com.example.finalsystem.Controller;

import com.example.finalsystem.Entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
public class PageController {
    //首页
    private boolean isLogin(HttpServletRequest request)
    {
        User user =(User)request.getSession().getAttribute("user");
        if (user!=null)
        {
            return true;
        }
        return false;
    }
    @GetMapping("/")
    public String show(Map<String,Object> map,HttpServletRequest request)
    {
        if (isLogin(request))
        {
            User user = (User)request.getSession().getAttribute("user");
            map.put("user",user);
            return "Home";
        }

        else
            return "Login";
    }
    //登陆请求页面
    @GetMapping("/login")
    public String showLogin(HttpServletRequest request)
    {
        if (isLogin(request))
            return "Home";
        else
            return "Login";
    }


    //登录完成后  页面跳转
    @GetMapping("/home")
    public String showIndex(Map<String,Object> map ,HttpServletRequest request)
    {
        if (isLogin(request))
        {
            //权限 系统管理员 SYSTEM  销售管理员 SALE  销售人员 STAFF  仓库管理员 REPOSITORY
            User user = (User)request.getSession().getAttribute("user");
            System.out.println("当前权限"+user.getUserrole());
            map.put("user",user);
            return "Home";
        }

        else
            return "Login";
    }

    //合同管理页面
    @GetMapping("/ContractManage/contractManage")
    public String showContractManage(HttpServletRequest request)
    {

        if (isLogin(request))
            return "ContractManage/contractManage";
        else
            return "UserNotLoginError";
    }

    //合同查询页面
    @GetMapping("/ContractManage/contractSearch")
    public String showContractSearch(HttpServletRequest request)
    {

        if (isLogin(request))
            return "ContractManage/contractSearch";
        else
            return "UserNotLoginError";
    }

    //清单管理页面
    @GetMapping("/ContractManage/contractBuy")
    public String showContractBuy(HttpServletRequest request)
    {

        if (isLogin(request))
            return "ContractManage/contractBuy";
        else
            return "UserNotLoginError";
    }

    //清单管理页面
    @GetMapping("/Statistics/statistics")
    public String showStatistics(HttpServletRequest request)
    {

        if (isLogin(request))
            return "Statistics/statistics";
        else
            return "UserNotLoginError";
    }

    @GetMapping("/welcome")
    public String showWelcome(HttpServletRequest request)
    {
        if (isLogin(request))
            return "Welcome";
        else
            return "UserNotLoginError";
    }

    //账户管理
    @GetMapping("/AccountManage/accountManage")
    public String showAccountManage(Map<String,Object> map ,HttpServletRequest request)
    {

        if (isLogin(request)){
            User user = (User)request.getSession().getAttribute("user");
            map.put("user",user);
            return "AccountManage/accountManage";
        }
        else
            return "UserNotLoginError";
    }
    //客户管理
    @GetMapping("/CustomerManage/customerManage")
    public String showCustomerManage(Map<String,Object> map ,HttpServletRequest request)
    {

        if (isLogin(request)){
            User user = (User)request.getSession().getAttribute("user");
            map.put("user",user);
            return "CustomerManage/customerManage";
        }
        else
            return "UserNotLoginError";
    }
    //仓库管理
    @GetMapping("/WarehouseManage/warehouseManage")
    public String showWarehouseManage(Map<String,Object> map ,HttpServletRequest request)
    {

        if (isLogin(request)){
            User user = (User)request.getSession().getAttribute("user");
            map.put("user",user);
            return "WarehouseManage/warehouseManage";
        }
        else
            return "UserNotLoginError";
    }

//    仓库管理-主页
    @GetMapping("/WarehouseManage/warehouseHome")
    public String showWarehouseHome(Map<String,Object> map ,HttpServletRequest request)
    {

        if (isLogin(request)){
            User user = (User)request.getSession().getAttribute("user");
            map.put("user",user);
            return "WarehouseManage/warehouseHome";
        }
        else
            return "UserNotLoginError";
    }

//    仓库管理-进货管理

    @GetMapping("/WarehouseManage/ingoodManage")
    public String showIngoodManage(Map<String,Object> map ,HttpServletRequest request)
    {

        if (isLogin(request)){
            User user = (User)request.getSession().getAttribute("user");
            map.put("user",user);
            return "WarehouseManage/ingoodManage";
        }
        else
            return "UserNotLoginError";
    }

//    仓库管理-出货管理

    @GetMapping("/WarehouseManage/outgoodManage")
    public String showOutgoodManage(Map<String,Object> map ,HttpServletRequest request)
    {

        if (isLogin(request)){
            User user = (User)request.getSession().getAttribute("user");
            map.put("user",user);
            return "WarehouseManage/outgoodManage";
        }
        else
            return "UserNotLoginError";
    }

//    仓库管理-库存管理
    @GetMapping("/WarehouseManage/inventoryManage")
    public String showinventoryManage(Map<String,Object> map ,HttpServletRequest request)
    {

        if (isLogin(request)){
            User user = (User)request.getSession().getAttribute("user");
            map.put("user",user);
            return "WarehouseManage/inventoryManage";
        }
        else
            return "UserNotLoginError";
    }

    @GetMapping("/Achievement/achievement")
    public String showAchievement(Map<String,Object> map ,HttpServletRequest request)
    {

        if (isLogin(request)){
            User user = (User)request.getSession().getAttribute("user");
            map.put("user",user);
            return "Achievement/achievement";
        }
        else
            return "UserNotLoginError";
    }
}

